<?php
$title = 'Edition produit';
$this->headTitle($title);
$this->headScript()->prependFile($this->basePath()."/js/foam/produit-editable.js");

// Get allergenes
$algValue = '[';
foreach ($allergenes as $allergene):
    $algValue .= $allergene->id_allergene.', ';
endforeach;
$algValue .= ']';
$algValue = str_replace(', ]', ']', $algValue);

// Get notes
$achat = $labo = $qualite = $marketing = $formation = $operation = $rd = '';

if($notes){
    $achat = $notes->achat;
    $labo = $notes->labo;
    $qualite = $notes->qualite;
    $marketing = $notes->marketing;
    $formation = $notes->formation;
    $operation = $notes->operation;
    $rd = $notes->rd;
}
?>
<div class="content-head">
    <h3>Edition produit</h3>
    <div class="toolbar">
        <button id="saveU-btn" class="btn btn-primary" onClick="saveUpdate('produit')">Enregistrer</button>
        &nbsp;&nbsp;&nbsp;
        <button id="reset-btn" class="btn pull-right" onClick="cancel('produit')">Fermer</button>
    </div>
</div>
<div class="content-body">
    <div id="msg" class="alert hide"></div>
    <p><b>Instructions:</b></p>
    <div class="add-container">
        <div class="add-prd-top">
            <a class="editable" 
               id="a-famille" 
               data-type="select" 
               data-value="<?php echo $produit->id_famille; ?>" 
               data-name="id_famille"
               data-source="<?php echo $this->url('foam/default', array('controller'=>'famille', 'action'=>'xeditable')) ?>" 
               data-original-title="Choisissez une famille"></a>
        </div>
        <div class="add-prd-left">
            <table width="100%">
                <tr>
                    <td width="15%" style="background:#9ACCFF;padding:5px"></td>
                    <td width="45%" style="background:#9ACCFF;padding:5px;vertical-align:top">
                        <a class="editable" 
                           id="a-libelle" 
                           data-type="text" 
                           data-name="libelle"
                           data-original-title="Saisissez un libellé"><?php echo $produit->libelle; ?></a>
                        <p></p>
                        <a class="editable" 
                           id="a-description" 
                           data-type="textarea" 
                           data-name="description"
                           data-original-title="Saisissez une description"><?php echo $produit->description; ?></a>
                    </td>                    
                    <td width="15%" class="td-prix">
                        <a class="editable" 
                           id="a-code" 
                           data-type="text" 
                           data-name="code"
                           data-original-title="Saisissez le code produit"><?php echo $produit->code; ?></a>
                        <p></p>
                        <a class="editable" 
                           id="a-prix" 
                           data-type="text" 
                           data-name="prix"
                           data-original-title="Saisissez le prix"><?php echo number_format($produit->prix,2,',', ' '); ?></a> &euro;
                    </td>
                    <td width="20%" class="td-autre-prix">
                        <span><u>Prix concession</u><br />
                            <a class="editable" 
                               id="a-prix_figaro" 
                               data-type="text" 
                               data-name="prix_concession"
                               data-original-title="Saisissez le prix"><?php echo number_format($produit->prix_concession,2,',', ' '); ?></a> &euro;
                        </span>
                        <p></p>
                        <span><u>Prix figaro</u><br />
                            <a class="editable" 
                               id="a-prix_concession" 
                               data-type="text" 
                               data-name="prix_figaro"
                               data-original-title="Saisissez le prix"><?php echo number_format($produit->prix_figaro,2,',', ' '); ?></a> &euro;
                        </span>
                    </td>
                </tr>
            </table>
            <p></p>
            <table width="100%">
                <tr>
                    <td width="55%">
                        <img src="<?php echo $this->basePath() ?>/img/foam/produits/colored pasta salad.jpg" />
                    </td>
                    <td width="20%" class="td-service">
                        <div>
                            <a class="editable" 
                               id="a-dlc" 
                               data-type="select" 
                               data-name="id_dlc"
                               data-value="<?php echo $produit->id_dlc; ?>"
                               data-source="<?php echo $this->url('foam/default', array('controller'=>'dlc', 'action'=>'xeditable')) ?>"
                               data-original-title="Choisissez un DLC"></a>
                        </div>
                        <div class="div-service">
                            <div style="margin: auto">
                            <a class="editable" 
                               id="a-service" 
                               data-type="select" 
                               data-name="id_service"
                               data-value="<?php echo $produit->id_service; ?>"
                               data-source="<?php echo $this->url('foam/default', array('controller'=>'service', 'action'=>'xeditable')) ?>"
                               data-original-title="Choisissez les services"></a>
                            </div>
                        </div>
                    </td>
                    <td width="20%" class="td-tva">
                        <span style="color:#FF6600"><b>TVA VAE</b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />
                            <a class="editable" 
                               id="a-tva_vae" 
                               data-type="select" 
                               data-name="tva_vae"
                               data-value="<?php echo $produit->tva_vae; ?>"
                               data-source="<?php echo $this->url('foam/default', array('controller'=>'tva', 'action'=>'xeditable')) ?>"
                               data-original-title="Choisissez un TVA"></a> %
                        </span>
                        <p></p>
                        <span style="color:#604A7B"><b>TVA SP</b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />
                            <a class="editable" 
                               id="a-tva_sp" 
                               data-type="select" 
                               data-name="tva_sp"
                               data-value="<?php echo $produit->tva_sp; ?>"
                               data-source="<?php echo $this->url('foam/default', array('controller'=>'tva', 'action'=>'xeditable')) ?>"
                               data-original-title="Choisissez un TVA"></a> %
                        </span>
                        <p></p>
                        <span class="span-contenant">
                            <a class="editable" 
                               id="a-contenant" 
                               data-type="select" 
                               data-name="id_contenant"
                               data-value="<?php echo $produit->id_contenant; ?>"
                               data-source="<?php echo $this->url('foam/default', array('controller'=>'contenant', 'action'=>'xeditable')) ?>"
                               data-original-title="Choisissez un contenant"></a>
                        </span>
                    </td>
                </tr>
                <tr>
                    <td colspan="3" class="td-production">
                        <div>
                            <span class="span-production">
                                <a class="editable" 
                                   id="a-production" 
                                   data-type="select" 
                                   data-name="id_production"
                                   data-value="<?php echo $produit->id_production; ?>"
                                   data-source="<?php echo $this->url('foam/default', array('controller'=>'production', 'action'=>'xeditable')) ?>"
                                   data-original-title="Choisissez un lieu de production"></a>
                            </span>
                        </div>
                    </td>
                </tr>
            </table>
            <p></p>
            <table width="100%">
                <tr>
                    <td colspan="3" class="td-debut_actif">
                        <div>
                            <span class="span-debut_actif">
                                dès le&nbsp;&nbsp;&nbsp;
                                <a class="editable" 
                                    id="a-debut_actif" 
                                    data-type="dateui" 
                                    data-name="debut_actif"
                                    data-viewformat="dd/mm/yyyy"
                                    data-value="<?php echo $produit->debut_actif; ?>" 
                                    data-original-title="Choisissez une date"></a>
                            </span>
                        </div>
                    </td>
                </tr>
                <tr>
                    <td width="55%" class="td-asavoir">
                        <a class="editable" 
                           id="a-asavoir" 
                           data-type="textarea" 
                           data-name="a_savoir"
                           data-original-title="Saisissez ce qu'il faut savoir"><?php echo $produit->a_savoir; ?></a>
                    </td>
                    <td width="20%" class="td-bio">
                        <span class="span-bio">
                            <a class="editable" 
                                id="a-bio" 
                                data-type="select" 
                                data-name="id_bio"
                                data-value="<?php echo $produit->id_bio; ?>"
                                data-source="<?php echo $this->url('foam/default', array('controller'=>'bio', 'action'=>'xeditable')) ?>"
                                data-original-title="Choisissez si bio"></a>
                        </span>                  
                    </td>
                    <td width="20%" class="td-ssfamille">
                        <span class="span-ssfamille">
                            <a class="editable"
                                id="a-ssfamille" 
                                data-type="select" 
                                data-name="id_ssfamille"
                                data-value="<?php echo $produit->id_ssfamille; ?>"
                                data-original-title="Choisissez une sous-famille"></a>
                        </span>
                    </td>
                </tr>
            </table>
            <p></p>
            <table width="100%">
                <tr>
                    <td colspan="3" class="td-allergene">
                        <span class="span-allergene-label">Allergènes</span>
                        <span class="span-allergene">
                            <a class="editable" 
                                id="a-allergene" 
                                data-type="checklist" 
                                data-name="id_allergene" 
                                data-value="<?php echo $algValue; ?>"
                                data-source="<?php echo $this->url('foam/default', array('controller'=>'allergene', 'action'=>'xeditable')) ?>"
                                data-original-title="Cocher un ou plusieurs"></a>
                        </span>
                    </td>
                </tr>
            </table>
        </div>
        <div class="add-prd-right">
            <table width="100%">
                <tr>
                    <td colspan="3" class="td-plateau">
                        <span class="span-plateau-label">Plateau livraison</span>
                        <span class="span-plateau">
                            <a class="editable" 
                                id="a-plateau" 
                                data-type="select" 
                                data-name="id_plateau" 
                                data-value="<?php echo $produit->id_plateau; ?>"
                                data-source="<?php echo $this->url('foam/default', array('controller'=>'plateau', 'action'=>'xeditable')) ?>"
                                data-original-title="Choisissez un plateau"></a>
                        </span>
                    </td>
                </tr>
                <tr>
                    <td class="td-autre-prix-right-label"><span class="span-plateau-label-fc">FC</span></td>
                    <td class="td-autre-prix-right-label"><span class="span-plateau-label-target">Target</span></td>
                    <td class="td-autre-prix-right-label"><span class="span-plateau-label-marge">Marge</span></td>
                </tr>
                <tr>
                    <td class="td-autre-prix-right">
                        <span class="span-plateau-fc">
                            <a class="editable" 
                                id="a-fc" 
                                data-type="text" 
                                data-name="fc"
                                data-original-title="Saisissez un prix"><?php echo number_format($produit->fc,2,',', ' '); ?></a> &euro;
                        </span>
                    </td>
                    <td class="td-autre-prix-right">
                        <span class="span-plateau-target">
                            <a class="editable" 
                                id="a-target" 
                                data-type="text" 
                                data-name="target"
                                data-original-title="Saisissez un prix"><?php echo number_format($produit->target,2,',', ' '); ?></a> &euro;
                        </span>
                    </td>
                    <td class="td-autre-prix-right">
                        <span class="span-plateau-marge">
                            <a class="editable" 
                                id="a-marge" 
                                data-type="text" 
                                data-name="marge"
                                data-original-title="Saisissez un pourcentage"><?php echo number_format($produit->marge,2,',', ' '); ?></a> %
                        </span>
                    </td>
                </tr>
                <tr>
                    <td colspan="2" class="td-volumes-estimes-label">
                        <span class="span-volumes-estimes-label">Volumes estimés</span>
                    </td>
                    <td class="td-volumes-estimes">
                        <span class="span-volumes-estimes">
                            <a class="editable" 
                                id="a-volumes-estimes" 
                                data-type="text" 
                                data-name="volumes_estimes" 
                                data-original-title="Saisissez un nombre"><?php echo $produit->volumes_estimes; ?></a> unités
                        </span>
                    </td>
                </tr>
                <tr>
                    <td class="td-autre-carac-label"><span class="span-label-dix">Série de 10</span></td>
                    <td class="td-autre-carac-label"><span class="span-label-hermes">Fiche Hermès</span></td>
                    <td class="td-autre-carac-label"><span class="span-label-formation">Fiche formation</span></td>
                </tr>
                <tr>
                    <td class="td-autre-carac">
                        <span class="span-dix">
                            <a class="editable" 
                                id="a-dix" 
                                data-type="select"
                                data-name="serie_10"
                                data-value="<?php echo $produit->serie_10; ?>"
                                data-source="[{value: 1, text: 'Oui'},{value: 0, text: 'Non'}]"></a>
                        </span>
                    </td>
                    <td class="td-autre-carac">
                        <span class="span-hermes">
                            <a class="editable" 
                                id="a-hermes" 
                                data-type="select"
                                data-name="fiche_hermes"
                                data-value="<?php echo $produit->fiche_hermes; ?>"
                                data-source="[{value: 1, text: 'Oui'},{value: 0, text: 'Non'}]"></a>
                        </span>
                    </td>
                    <td class="td-autre-carac">
                        <span class="span-formation">
                            <a class="editable" 
                                id="a-formation" 
                                data-type="select" 
                                data-name="fiche_formation"
                                data-value="<?php echo $produit->fiche_formation; ?>"
                                data-source="[{value: 1, text: 'Oui'},{value: 0, text: 'Non'}]"></a>
                        </span>
                    </td>
                </tr>
                <tr>
                    <td colspan="3" class="td-note">
                        <div>
                            <p>Notes</p>
                            <table class="notelist">
                                <tr>
                                    <td class="ntleft">achat</td>
                                    <td class="ntright">
                                        <a class="editable notes"
                                            data-type="text" 
                                            data-name="achat"
                                            data-original-title=""><?php echo $achat; ?></a>    
                                    </td>
                                </tr>
                                <tr>
                                    <td class="ntleft">labo</td>
                                    <td class="ntright">
                                        <a class="editable notes"
                                            data-type="text" 
                                            data-name="labo"
                                            data-original-title=""><?php echo $labo; ?></a>    
                                    </td>
                                </tr>
                                <tr>
                                    <td class="ntleft">qualité</td>
                                    <td class="ntright">
                                        <a class="editable notes"
                                            data-type="text" 
                                            data-name="qualite"
                                            data-original-title=""><?php echo $qualite; ?></a>    
                                    </td>
                                </tr>
                                <tr>
                                    <td class="ntleft">marketing</td>
                                    <td class="ntright">
                                        <a class="editable notes"
                                            data-type="text" 
                                            data-name="marketing"
                                            data-original-title=""><?php echo $marketing; ?></a>    
                                    </td>
                                </tr>
                                <tr>
                                    <td class="ntleft">formation</td>
                                    <td class="ntright">
                                        <a class="editable notes"
                                            data-type="text" 
                                            data-name="formation"
                                            data-original-title=""><?php echo $formation; ?></a>    
                                    </td>
                                </tr>
                                <tr>
                                    <td class="ntleft">opération</td>
                                    <td class="ntright">
                                        <a class="editable notes"
                                            data-type="text" 
                                            data-name="operation"
                                            data-original-title=""><?php echo $operation; ?></a>    
                                    </td>
                                </tr>
                                <tr>
                                    <td class="ntleft">R&D</td>
                                    <td class="ntright">
                                        <a class="editable notes"
                                            data-type="text" 
                                            data-name="rd"
                                            data-original-title=""><?php echo $rd; ?></a>    
                                    </td>
                                </tr>
                            </table>
                        </div>
                    </td>
                </tr>
            </table>            
        </div>
        <div class="add-prd-bottom"></div>
        <input type="hidden" id="id_famille_value" value="<?php echo $produit->id_famille; ?>" />
        <a class="editable a-hidden" 
            id="a-id_produit" 
            data-type="text" 
            data-name="id_produit"><?php echo $produit->id_produit; ?></a>
    </div>   
</div>
<div id="dialog-form"></div>
